import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router);

// 顶层路由
import App from '../App'

const Layout = r => require.ensure([], () => r(require('src/page/layout/layout')), 'layout');

export const constantRouterMap = [{
    path: '/',
    component: App, //顶层路由，对应index.html
    children: [ //二级路由。对应App.vue
        //登录
        {
            path: '/login',
            component: r => require.ensure([], () => r(require('../page/login/login')), 'layout')
        },
        //地址为空时跳转main页面
        {
            path: '',
            component: Layout,
            redirect: 'main',
            children: [
                {
                    path: 'main',
                    component: r => require.ensure([], () => r(require('../page/main/main')), 'layout'),
                    name: '主页',
                    meta: { requiresAuth: true }
                }
            ]
        },
        // 企业计划
        {
            path: '',
            component: Layout,
            redirect: 'profile',
            children: [
                {
                    path: 'profile',
                    component: r => require.ensure([], () => r(require('../page/profile/profile')), 'layout'),
                    name: '企业计划',
                    meta: { requiresAuth: true }
                }
            ]
        },
        // 语言管理
        {
            path: '',
            component: Layout,
            redirect: 'language',
            children: [
                {
                    path: '/language',
                    component: r => require.ensure([], () => r(require('../page/language/index')), 'layout'),
                    name: '语言管理',
                    meta: { requiresAuth: true }
                }
            ]
        },
        // 机构管理
        {
            path: '',
            component: Layout,
            redirect: 'org_manage',
            children: [
                {
                    path: '/organization/manage',
                    component: r => require.ensure([], () => r(require('../page/org_manage/index')), 'layout'),
                    name: '机构管理',
                    meta: { requiresAuth: true }
                }
            ]
        },
        // 机构管理 -> 激活
        {
            path: '',
            component: Layout,
            redirect: 'org_manage',
            children: [
                {
                    path: '/organization/activate',
                    component: r => require.ensure([], () => r(require('../page/org_manage/activate')), 'layout'),
                    name: '机构激活',
                    meta: { requiresAuth: true }
                }
            ]
        },
        // 机构管理 -> 激活 -> 企业信息
        {
            path: '',
            component: Layout,
            redirect: 'org_manage',
            children: [
                {
                    path: '/organization/activate/:id',
                    component: r => require.ensure([], () => r(require('../page/org_manage/enterpriceDetail')), 'layout'),
                    name: '激活信息',
                    meta: { requiresAuth: true }
                }
            ]
        },
        // 机构 => 课程创建
        {
            path: '',
            component: Layout,
            redirect: 'org_manage',
            children: [
                {
                    path: '/org/course',
                    component: r => require.ensure([], () => r(require('../page/org_manage/course/index')), 'layout'),
                    name: '课程管理',
                    meta: { requiresAuth: true }
                }
            ]
        },
        // 机构 => 课程创建 => 添加课程
        {
            path: '',
            component: Layout,
            redirect: 'org_manage',
            children: [
                {
                    path: '/org/course/add',
                    component: r => require.ensure([], () => r(require('../page/org_manage/course/add')), 'layout'),
                    name: '添加课程',
                    meta: { requiresAuth: true }
                }
            ]
        },
        // 机构 => 课程创建 => 编辑课程
        {
            path: '',
            component: Layout,
            redirect: 'org_manage',
            children: [
                {
                    path: '/org/course/edite/:id',
                    component: r => require.ensure([], () => r(require('../page/org_manage/course/add')), 'layout'),
                    name: '添加课程',
                    meta: { requiresAuth: true }
                }
            ]
        },
        // 机构 => 课程创建 => 购买用户
        {
            path: '',
            component: Layout,
            redirect: 'org_manage',
            children: [
                {
                    path: '/org/course/buyer/:id',
                    component: r => require.ensure([], () => r(require('../page/org_manage/course/buyer')), 'layout'),
                    name: '购买用户',
                    meta: { requiresAuth: true }
                }
            ]
        },
        // 机构 => 专栏管理
        {
            path: '',
            component: Layout,
            redirect: 'org_manage',
            children: [
                {
                    path: '/org/album',
                    component: r => require.ensure([], () => r(require('../page/org_manage/album/index')), 'layout'),
                    name: '专栏管理',
                    meta: { requiresAuth: true }
                }
            ]
        },
        // 机构 => 专栏管理 =》 课程列表
        {
            path: '',
            component: Layout,
            redirect: 'org_manage',
            children: [
                {
                    path: '/org/album/:id/course',
                    component: r => require.ensure([], () => r(require('../page/org_manage/album/course/index')), 'layout'),
                    name: '课程管理',
                    meta: { requiresAuth: true }
                }
            ]
        },
        // 机构 => 专栏管理 => 课程创建 => 添加课程
        {
            path: '',
            component: Layout,
            redirect: 'org_manage',
            children: [
                {
                    path: '/org/album/:albumId/course/add',
                    component: r => require.ensure([], () => r(require('../page/org_manage/album/course/add')), 'layout'),
                    name: '添加课程',
                    meta: { requiresAuth: true }
                }
            ]
        },
        // 机构 => 课程创建 => 编辑课程
        {
            path: '',
            component: Layout,
            redirect: 'org_manage',
            children: [
                {
                    path: '/org/album/course/edite/:id',
                    component: r => require.ensure([], () => r(require('../page/org_manage/album/course/add')), 'layout'),
                    name: '添加课程',
                    meta: { requiresAuth: true }
                }
            ]
        },
        // 机构 => 课程创建 => 购买用户
        {
            path: '',
            component: Layout,
            redirect: 'org_manage',
            children: [
                {
                    path: '/org/album/buyer/:id',
                    component: r => require.ensure([], () => r(require('../page/org_manage/album/buyer')), 'layout'),
                    name: '购买用户',
                    meta: { requiresAuth: true }
                }
            ]
        },
        // 机构 => 课程创建 => 购买用户
        {
            path: '',
            component: Layout,
            redirect: 'org_manage',
            children: [
                {
                    path: '/org/album/course/buyer/:id',
                    component: r => require.ensure([], () => r(require('../page/org_manage/album/buyer')), 'layout'),
                    name: '购买用户',
                    meta: { requiresAuth: true }
                }
            ]
        },
        // 账户管理->账户明细
        {
            path: '',
            component: Layout,
            redirect: 'account',
            children: [
                {
                    path: 'account/detail',
                    component: r => require.ensure([], () => r(require('../page/account/detail/index')), 'layout'),
                    name: '账户明细',
                    meta: { requiresAuth: true }
                }
            ]
        },
        // 账户管理->提现请求
        {
            path: '',
            component: Layout,
            redirect: 'account',
            children: [
                {
                    path: 'account/cashreq',
                    component: r => require.ensure([], () => r(require('../page/account/cashreq/index')), 'layout'),
                    name: '提现请求',
                    meta: { requiresAuth: true }
                }
            ]
        },
        // 账户管理->管理员查看旗下企业账户明细
        {
            path: '',
            component: Layout,
            redirect: 'account',
            children: [
                {
                    path: 'account/detail/:id',
                    component: r => require.ensure([], () => r(require('../page/account/detail/index')), 'layout'),
                    name: '企业账户明细',
                    meta: { requiresAuth: true }
                }
            ]
        },
        // 账户管理-》用户提现
        {
            path: '',
            component: Layout,
            redirect: 'account',
            children: [
                {
                    path: 'user/userCash',
                    component: r => require.ensure([], () => r(require('../page/account/userAdvance/index')), 'layout'),
                    name: '用户提现',
                    meta: { requiresAuth: true }
                }
            ]
        },
        // 账户管理-》所有用户管理 【管理员】
        {
            path: '',
            component: Layout,
            redirect: 'account',
            children: [
                {
                    path: 'user/all',
                    component: r => require.ensure([], () => r(require('../page/user/user/user')), 'layout'),
                    name: '用户',
                    meta: { requiresAuth: true }
                }
            ]
        },
        // 账户管理-》用户审核
        {
            path: '',
            component: Layout,
            redirect: 'account',
            children: [
                {
                    path: 'user/auditing',
                    component: r => require.ensure([], () => r(require('../page/user/auditing/auditing')), 'layout'),
                    name: '用户审核',
                    meta: { requiresAuth: true }
                }
            ]
        },
        // 合同管理-合同发起
        {
            path: '',
            component: Layout,
            redirect: 'contract',
            children: [
                {
                    path: 'contract/offer',
                    component: r => require.ensure([], () => r(require('../page/contract/offer/index')), 'layout'),
                    name: '合同发起',
                    meta: { requiresAuth: true }
                }
            ]
        },
        // 合同管理-合同签署
        {
            path: '',
            component: Layout,
            redirect: 'contract',
            children: [
                {
                    path: 'contract/sign',
                    component: r => require.ensure([], () => r(require('../page/contract/sign/index')), 'layout'),
                    name: '合同签署',
                    meta: { requiresAuth: true }
                }
            ]
        },
        // 合同管理-合同查看
        {
            path: '',
            component: Layout,
            redirect: 'contract',
            children: [
                {
                    path: 'contract/view',
                    component: r => require.ensure([], () => r(require('../page/contract/view/index')), 'layout'),
                    name: '合同查看',
                    meta: { requiresAuth: true }
                }
            ]
        },
        // 合同管理-合同查看
        {
            path: '',
            component: Layout,
            redirect: 'contract',
            children: [
                {
                    path: 'contract/org',
                    component: r => require.ensure([], () => r(require('../page/contract/org/index')), 'layout'),
                    name: '机构合同',
                    meta: { requiresAuth: true }
                }
            ]
        },
        // 用户管理-受邀注册用户
        {
            path: '',
            component: Layout,
            redirect: 'user',
            children: [
                {
                    path: 'user/invite',
                    component: r => require.ensure([], () => r(require('../page/user/invite/index')), 'layout'),
                    name: '受邀注册用户',
                    meta: { requiresAuth: true }
                }
            ]
        },
        // 用户管理-课程购买用户
        {
            path: '',
            component: Layout,
            redirect: 'purchase',
            children: [
                {
                    path: 'user/purchase',
                    component: r => require.ensure([], () => r(require('../page/user/purchase/index')), 'layout'),
                    name: '课程购买用户',
                    meta: { requiresAuth: true }
                }
            ]
        },
        // 用户管理-内测用户配置
        {
            path: '',
            component: Layout,
            redirect: 'innertest',
            children: [
                {
                    path: 'user/inner/test',
                    component: r => require.ensure([], () => r(require('../page/user/innertest/index')), 'layout'),
                    name: '内测用户配置',
                    meta: { requiresAuth: true }
                }
            ]
        },
        // 结算管理-结算总览
        {
            path: '',
            component: Layout,
            redirect: 'browse',
            children: [
                {
                    path: 'settlement/browse',
                    component: r => require.ensure([], () => r(require('../page/settlement/browse/index')), 'layout'),
                    name: '结算总览',
                    meta: { requiresAuth: true }
                }
            ]
        },
        // 模板管理
        {
            path: '',
            component: Layout,
            redirect: 'template',
            children: [
                {
                    path: 'template',
                    component: r => require.ensure([], () => r(require('../page/template/index')), 'layout'),
                    name: '模板管理',
                    meta: { requiresAuth: true }
                }
            ]
        },
        // 模板管理 ->添加
        {
            path: '',
            component: Layout,
            redirect: 'add',
            children: [
                {
                    path: 'template/add',
                    component: r => require.ensure([], () => r(require('../page/template/add')), 'layout'),
                    name: '模板添加',
                    meta: { requiresAuth: true }
                }
            ]
        },
        // 模板管理 ->编辑
        {
            path: '',
            component: Layout,
            redirect: 'add',
            children: [
                {
                    path: '/template/:id',
                    component: r => require.ensure([], () => r(require('../page/template/add')), 'layout'),
                    name: '模板编辑',
                    meta: { requiresAuth: true }
                }
            ]
        },
        // 人工翻译
        {
            path: '',
            component: Layout,
            redirect: 'translate',
            children: [
                {
                    path: '/translate',
                    component: r => require.ensure([], () => r(require('../page/translate/index')), 'layout'),
                    name: '人工翻译',
                    meta: { requiresAuth: true }
                }
            ]
        },
        // 人工翻译 ->添加
        {
            path: '',
            component: Layout,
            redirect: 'add',
            children: [
                {
                    path: 'translate/add',
                    component: r => require.ensure([], () => r(require('../page/translate/add')), 'layout'),
                    name: '人工翻译添加',
                    meta: { requiresAuth: true }
                }
            ]
        },
        // 人工翻译 ->编辑
        {
            path: '',
            component: Layout,
            redirect: 'add',
            children: [
                {
                    path: '/translate/:id',
                    component: r => require.ensure([], () => r(require('../page/translate/add')), 'layout'),
                    name: '人工翻译编辑',
                    meta: { requiresAuth: true }
                }
            ]
        },

        // 项目管理
        {
            path: '',
            component: Layout,
            redirect: 'project',
            children: [
                {
                    path: '/project',
                    component: r => require.ensure([], () => r(require('../page/project/project')), 'layout'),
                    name: '项目管理',
                    meta: { requiresAuth: true }
                }
            ]
        },
        // 项目管理-> 机构价格编辑
        {
            path: '',
            component: Layout,
            redirect: 'project',
            children: [
                {
                    path: '/project/enterprice/:id',
                    component: r => require.ensure([], () => r(require('../page/project/enterprice')), 'layout'),
                    name: '课程价格管理',
                    meta: { requiresAuth: true }
                }
            ]
        },
        // 课程管理
        {
            path: '/course',
            component: Layout,
            redirect: 'course',
            children: [
                {
                    path: '',
                    component: r => require.ensure([], () => r(require('../page/course/course')), 'layout'),
                    name: '课程管理',
                    meta: { requiresAuth: true }
                },
                // 课程管理 -> 详细列表
                {
                    path: ':id',
                    component: r => require.ensure([], () => r(require('../page/course/courseVideoList')), 'layout'),
                    name: '课程列表',
                    meta: { requiresAuth: true }
                },
                // 课程管理 -- 课程列表 --添加
                {
                    path: 'video/add',
                    component: r => require.ensure([], () => r(require('../page/course/add')), 'layout'),
                    name: '添加课程',
                    meta: { requiresAuth: true }
                },
                // 课程管理 -- 课程列表 --添加
                {
                    path: 'video/add/:categoryId',
                    component: r => require.ensure([], () => r(require('../page/course/add')), 'layout'),
                    name: '修改课程',
                    meta: { requiresAuth: true }
                },
                // 课程管理 -- 课程列表 --修改
                {
                    path: 'video/update/:categoryId/:id',
                    component: r => require.ensure([], () => r(require('../page/course/add')), 'layout'),
                    name: '修改课程',
                    meta: { requiresAuth: true }
                }
            ]
        },
        // 活动列表
        {
            path: '',
            component: Layout,
            redirect: 'active',
            children: [
                {
                    path: '/activate',
                    component: r => require.ensure([], () => r(require('../page/activate/index')), 'layout'),
                    name: '商品',
                    meta: { requiresAuth: true }
                }
            ]
        },
        // 活动--添加
        {
            path: '',
            component: Layout,
            redirect: 'active-add',
            children: [
                {
                    path: '/activate/add',
                    component: r => require.ensure([], () => r(require('../page/activate/add')), 'layout'),
                    name: '添加商品',
                    meta: { requiresAuth: true }
                }
            ]
        },
        // 活动--购买用户列表
        {
            path: '',
            component: Layout,
            redirect: 'active-add',
            children: [
                {
                    path: '/activate/buyer/:id',
                    component: r => require.ensure([], () => r(require('../page/activate/buyer')), 'layout'),
                    name: '购买用户',
                    meta: { requiresAuth: true }
                }
            ]
        },
        // 活动--添加
        {
            path: '',
            component: Layout,
            redirect: 'active-update',
            children: [
                {
                    path: '/activate/:id',
                    component: r => require.ensure([], () => r(require('../page/activate/add')), 'layout'),
                    name: '编辑商品',
                    meta: { requiresAuth: true }
                }
            ]
        },
        // 404
        {
            path: '*',
            component: r => require.ensure([], () => r(require('../page/errorPage/404')), 'layout')
        },
    ]
}];

export default new Router({
    routes: constantRouterMap,
    // scrollBehavior(to, from, savedPosition) {
    //     if (savedPosition) {
    //         return savedPosition
    //     } else {
    //         console.log(from.meta);
    //         if (from.meta.keepAlive) {
    //             from.meta.savedPosition = document.body.scrollTop;
    //         }
    //         return { x: 0, y: to.meta.savedPosition || 0 }
    //     }
    // }
})
